#include "graphics.h"
//#include <GL/glfw.h>
#include "texture.h"

namespace griselda
{
    namespace graphics
    {
        const int WND_WIDTH = 640;
        const int WND_HEIGHT = 480;

        void render()
        {
            glClear(GL_COLOR_BUFFER_BIT);
            glEnable(GL_TEXTURE_2D);

            glBegin(GL_QUADS);
                glTexCoord2f(0.0f, 0.0f);
                glVertex2f(0.0f, 0.0f);
                glTexCoord2f(0.0f, 1.0f);
                glVertex2f(32.0f, 0.0f);
                glTexCoord2f(1.0f, 1.0f);
                glVertex2f(32.0f, 32.0f);
                glTexCoord2f(1.0f, 0.0f);
                glVertex2f(0.0f, 32.0f);
            glEnd();

            glFlush();
        }

        /**
         * Initializes OpenGL and the glfw stuff and creates a window.
         *
         * @param argc argument count
         * @param argv arguments
         */
        bool init()
        {
            // initialize glfw and create a window
            if(!glfwInit())
            {
                return false;
            }

            // window properties
            glfwSetWindowTitle("The Legend of Griselda");

            if(!glfwOpenWindow(WND_WIDTH, WND_HEIGHT, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
            {
                glfwTerminate();
                return false;
            }

            // initialize opengl
            glClearColor(0.0, 0.0, 0.0, 0.0);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrtho(0, WND_WIDTH, 0, WND_HEIGHT, 0, 128);

            // culling
            glCullFace(GL_BACK);
            glEnable(GL_CULL_FACE);

            return true;
        }
    }
}

